package main

import (
	"gitee.com/scottq/go-framework/src/miscs"
	v1job "gitee.com/scottq/go-framework/src/v1/jobserver"
	"time"
)

func main() {

	//第一个job（5秒后执行结束）
	job := v1job.NewJob("printX", func() {
		for i := 0; i <= 10; i++ {
			println("job", i, time.Now().Format(miscs.DateTimeLayout))
			time.Sleep(time.Millisecond * 500)
		}
	})
	job.SetCoNum(2)

	//第二个job（定时执行的，每秒执行）
	sch := v1job.NewJobScheduler("scheduler", time.Second, v1job.NewJob("printX", func() {
		println("scheduler", time.Now().Format(miscs.DateTimeLayout))
	}))

	runner := v1job.NewJobRunner("mixJobs")
	runner.AddJob(job)
	runner.AddJob(sch)
	//只执行一次
	runner.AddExecute("printTime", func() {
		println("executor", time.Now().Format(miscs.DateTimeLayout))
	})

	//15秒后手动停止定时任务
	go func() {
		time.Sleep(time.Second * 15)
		println("stop scheduler", time.Now().Format(miscs.DateTimeLayout))
		sch.Stop()
	}()

	runner.Run()
	println("end")
}
